package cn.ges.movie.config.webmvcconfigurationsupport

import com.ges.common.config.autowired.AutowiredUserId
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Configuration
import org.springframework.web.method.support.HandlerMethodArgumentResolver
import org.springframework.web.servlet.config.annotation.CorsRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

/**
 * web启动相关
 */
@Configuration
open class WebMvcConfigurationSupportImpl() : WebMvcConfigurer {

    val log: Logger = LoggerFactory.getLogger(this::class.java)

    @Autowired
    lateinit var autowiredUserId: AutowiredUserId

    override fun addCorsMappings(registry: CorsRegistry) {
        super.addCorsMappings(registry);
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedMethods("POST","GET")
                .allowedOrigins("*");
    }

    override fun addArgumentResolvers(argumentResolvers: MutableList<HandlerMethodArgumentResolver?>) {
        // userId 注入
        log.info("[userId自动注入]初始化 userId自动注入")
        argumentResolvers.add(autowiredUserId)
        super.addArgumentResolvers(argumentResolvers)
    }

}